/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
    }
}

class Solution {

 public static void main(String[] args) {
  int[] arr1 = {-1};
  int[] arr2 = {-1};
  TreeNode node = buildTree(arr1,arr2);
  System.out.println("skdg");
 }
  public static int rootIndex = 0;
  public static TreeNode buildTree(int[] preorder, int[] inorder) {
      rootIndex = 0;
     return buildTreeWay(preorder,inorder,0,inorder.length - 1);
  }

 //构建二叉树
  public static TreeNode buildTreeWay(int[] preorder,int[] inorder,int start,int end) {
    if(start > end) {
     return null;
    }
    TreeNode root = new TreeNode(preorder[rootIndex]);
    for(int i = start; i <= end; i++) {
     if (inorder[i] == preorder[rootIndex]) {
      rootIndex++;
      root.left = buildTreeWay(preorder, inorder, start, i - 1);
      root.right = buildTreeWay(preorder, inorder, i + 1, end);
      return root;
     }
    }
      return null;
  }
}

class Test1{

    //根据二叉树创建字符串
    public String tree2str(TreeNode root) {
        if(root == null) {
            return null;
        }
        StringBuilder s = new StringBuilder();
        preOrder(root,s);
        return s.toString();
    }

    public void preOrder(TreeNode root,StringBuilder s) {
        s.append(root.val);
        if(root.left != null) {
            s.append("(");
            preOrder(root.left,s);
            s.append(")");
        }else {
            if(root.right != null) {
                s.append("()");
            }
        }
        if(root.right != null) {
            s.append("(");
            preOrder(root.right,s);
            s.append(")");
        }
    }
    public static void main(String[] args) {

    }
}
